package com.ruoyi.web.controller.pdd;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TlPddMallTemplate;
import com.ruoyi.system.service.ITlPddMallTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拼多多运费模板Controller
 *
 * @author ruoyi
 * @date 2023-11-14
 */
@RestController
@RequestMapping("/system/template")
public class TlPddMallTemplateController extends BaseController
{
    @Autowired
    private ITlPddMallTemplateService tlPddMallTemplateService;

    /**
     * 查询拼多多运费模板列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TlPddMallTemplate tlPddMallTemplate)
    {
        Long userId = getUserId();
        if(userId!=1L){
            tlPddMallTemplate.setUserId(userId);
        }
        startPage();
        List<TlPddMallTemplate> list = tlPddMallTemplateService.selectTlPddMallTemplateList(tlPddMallTemplate);
        return getDataTable(list);
    }

    /**
     * 查询拼多多运费模板列表
     */
    @GetMapping("/listAll")
    public List<TlPddMallTemplate> listAll(TlPddMallTemplate tlPddMallTemplate)
    {
        Long userId = getUserId();
        if(userId!=1L){
            tlPddMallTemplate.setUserId(userId);
        }
        return tlPddMallTemplateService.selectTlPddMallTemplateList(tlPddMallTemplate);
    }

    /**
     * 导出拼多多运费模板列表
     */
    @Log(title = "拼多多运费模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TlPddMallTemplate tlPddMallTemplate)
    {
        List<TlPddMallTemplate> list = tlPddMallTemplateService.selectTlPddMallTemplateList(tlPddMallTemplate);
        ExcelUtil<TlPddMallTemplate> util = new ExcelUtil<TlPddMallTemplate>(TlPddMallTemplate.class);
        util.exportExcel(response, list, "拼多多运费模板数据");
    }

    /**
     * 获取拼多多运费模板详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tlPddMallTemplateService.selectTlPddMallTemplateById(id));
    }

    /**
     * 新增拼多多运费模板
     */
    @Log(title = "拼多多运费模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TlPddMallTemplate tlPddMallTemplate)
    {
        return toAjax(tlPddMallTemplateService.insertTlPddMallTemplate(tlPddMallTemplate));
    }

    /**
     * 修改拼多多运费模板
     */
    @Log(title = "拼多多运费模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TlPddMallTemplate tlPddMallTemplate)
    {
        return toAjax(tlPddMallTemplateService.updateTlPddMallTemplate(tlPddMallTemplate));
    }

    /**
     * 删除拼多多运费模板
     */
    @Log(title = "拼多多运费模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tlPddMallTemplateService.deleteTlPddMallTemplateByIds(ids));
    }
}
